//引入模块
const koa = require('koa');
const bodyP = require('koa-body');
const views = require('koa-views')


let app = new koa();

//配置ejs模板要放在最前面
app.use(views('views', { map: { html: "ejs" } }))

app.use(bodyP());

let mod = {
    "/": ["get", async (ctx) => {

        await ctx.render('login', {

        })
    }],
    "/index": ["get", async (ctx) => {

        await ctx.render('index', {

        })
    }],

    "/news": ["get", async (ctx) => {
        await ctx.render('news', {

        })
    }],
    "/doLogin": ["post", async (ctx) => {

        let uName = ctx.request.body.username;
        let pwd = ctx.request.body.password;

        if (uName == 'admin' && pwd == '123') {

            ctx.redirect('/index');
        } else {
            ctx.body = "账号或密码错误";
        }

    }]
}


//暴露模块
module.exports = mod;